define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/order/index' + location.search,
                    // add_url: 'order/order/add',
                    edit_url: 'order/order/edit',
                    del_url: 'order/order/del',
                    multi_url: 'order/order/multi',
                    import_url: 'order/order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'store_id', title: __('Store_id')},
                        {field: 'technician_id', title: __('Technician_id')},
                        // {field: 'address_id', title: __('Address_id')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'serve_id', title: __('Serve_id')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE'},
                        {field: 'order_time', title: __('Order_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order_note', title: __('Order_note'), operate: 'LIKE'},
                        {field: 'quantity', title: __('Quantity')},
                        {field: 'distance', title: __('Distance'), operate:'BETWEEN'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'uname', title: __('Uname'), operate: 'LIKE'},
                        {field: 'gender', title: __('Gender'), searchList: {"0":__('Gender 0'),"1":__('Gender 1')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'departure_time', title: __('Departure_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'beginserve_time', title: __('Beginserve_time'), operate: 'LIKE'},
                        {field: 'endserve_time', title: __('Endserve_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'cancel_time', title: __('Cancel_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'receiving_time', title: __('Receiving_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order_amount', title: __('Order_amount'), operate:'BETWEEN'},
                        {field: 'order_amounts', title: __('Order_amounts'), operate:'BETWEEN'},
                        {field: 'mileagefee', title: __('Mileagefee'), operate:'BETWEEN'},
                        {field: 'coupon_money', title: __('Coupon_money'), operate:'BETWEEN'},
                        {field: 'coupon_id', title: __('Coupon_id')},
                        {field: 'order_status', title: __('Order_status'), searchList: {"0":__('Order_status 0'),"1":__('Order_status 1'),"2":__('Order_status 2'),"3":__('Order_status 3'),"4":__('Order_status 4'),"5":__('Order_status 5'),"6":__('Order_status 6'),"7":__('Order_status 7'),"8":__('评价完成'),"9":__('Order_status 9'),"10":__('Order_status 10'),"11":__('Order_status 11'),"12":__('Order_status 12'),"13":__('Order_status 13'),"14":__('Order_status 14')}, formatter: Table.api.formatter.status},
                        {field: 'refund_reason', title: __('Refund_reason'), operate: 'LIKE'},
                        {field: 'is_store_order', title: __('Is_store_order'), searchList: {"0":__('Is_store_order 0'),"1":__('Is_store_order 1')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'store_money', title: __('Store_money'), operate:'BETWEEN'},
                        {field: 'platform_money', title: __('Platform_money'), operate:'BETWEEN'},
                        {field: 'technician_price', title: __('Technician_price'), operate:'BETWEEN'},
                        {field: 'refund_status', title: __('Refund_status')},
                        {field: 'refund_money', title: __('Refund_money'), operate:'BETWEEN'},
                        {field: 'payment_type', title: __('Payment_type'), searchList: {"wechat":__('Payment_type wechat'),"alipay":__('Payment_type alipay'),"3":__('Payment_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'comment_time', title: __('Comment_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'add_bell_time', title: __('Add_bell_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'arrive_time', title: __('Arrive_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'u_address', title: __('U_address'), operate: 'LIKE'},
                        {field: 'serve_time', title: __('服务时间(分钟)'), operate:'false'},
                        // {field: 'change_address', title: __('Change_address'), searchList: {"1":__('Change_address 1'),"2":__('Change_address 2')}, formatter: Table.api.formatter.normal},
                        {field: 'appointment_time', title: __('Appointment_time'), operate: 'LIKE'},
                        {field: 'first_level_commission', title: __('First_level_commission'), operate:'BETWEEN'},
                        {field: 'sub_commission', title: __('Sub_commission'), operate:'BETWEEN'},
                        // {field: 'lat', title: __('Lat'), operate:'BETWEEN'},
                        // {field: 'lon', title: __('Lon'), operate:'BETWEEN'},
                        {field: 'detail', title: __('Detail'), operate: 'LIKE'},
                        {field: 'serve.serve_name', title: __('Serve.serve_name'), operate: 'LIKE'},
                        {field: 'technician.technician_name', title: __('Technician.technician_name'), operate: 'LIKE'},
                        {field: 'technician.technician_avatar', title: __('Technician.technician_avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'store.name', title: __('Store.name'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('按钮组'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'servelog',
                                    text: __('订单评价列表'),
                                    title: __('评价列表'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'order/ordercomment/index?id={ids}',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ],

                            formatter: Table.api.formatter.buttons
                        }
                        ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
